//本文件根据十六进制数据 返回 实际有效的数据

//Co2: Hex -> Dec
function handleCo2DataHex2Dec(valid_data) {
  let temp = `0x${valid_data[0].toString(16)}${valid_data[1].toString(16)}`;
  return Number.parseInt(temp);
}
//Temperature
function handleTemperatureDataHex2Dec(valid_data) {
  let a = `${valid_data[0].toString()}`;
  let b = `${valid_data[1].toString()}`;
  if (Number.parseInt(a) < 10) {
    a = `0${valid_data[0].toString(16)}`;
  } else {
    a = `${valid_data[0].toString(16)}`;
  }
  if (Number.parseInt(b) < 10) {
    b = `0${valid_data[1].toString(16)}`;
  } else {
    b = `${valid_data[1].toString(16)}`;
  }
  return Number.parseInt(`0x${a}${b}`) / 10;
}
//Humidty
function handleHumidtyDataHex2Dec(valid_data) {
  let a = `${valid_data[2].toString()}`;
  let b = `${valid_data[3].toString()}`;
  if (Number.parseInt(a) < 10) {
    a = `0${valid_data[2].toString(16)}`;
  } else {
    a = `${valid_data[2].toString(16)}`;
  }
  if (Number.parseInt(b) < 10) {
    b = `0${valid_data[3].toString(16)}`;
  } else {
    b = `${valid_data[3].toString(16)}`;
  }
  return Number.parseInt(`0x${a}${b}`) / 10;
}

module.exports.handleCo2DataHex2Dec = handleCo2DataHex2Dec;
module.exports.handleTemperatureDataHex2Dec = handleTemperatureDataHex2Dec;
module.exports.handleHumidtyDataHex2Dec = handleHumidtyDataHex2Dec;
